package com.hzit.manager.entity;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * 类名：
 * 作者：WF
 * 功能：
 */

public class Student implements BeanNameAware, BeanFactoryAware, ApplicationContextAware,
		InitializingBean, DisposableBean{

	@Override
	public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
		System.out.println("2. 设置beanFactory");
	}

	@Override
	public void setBeanName(String name) {
		System.out.println("1. 设置beanName");
	}

	// 默认初始化方法
	public void myPostConstruct() {
		System.out.println("7. Student#myPostConstruct() 执行");
	}
	@Override
	public void destroy() throws Exception {
		System.out.println("销毁bean");
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		System.out.println("6. 属性设置完成后afterPropertiesSet");
	}

	// 自定义初始化方法
	@PostConstruct
	public void springPostConstruct() {
		System.out.println("5. @PostConstruct 自定义初始化方法执行");
	}
	//默认销毁方法
	public void myPreDestroy() {
		System.out.println("Student#myPreDestroy 执行");
	}

	//自定义销毁方法
	@PreDestroy
	public void springPreDestroy() {
		System.out.println("@PreDestroy自定义销毁方法执行");
	}

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		System.out.println("3. 设置applicationContext");
	}
}
